window.onload = function() {
	seajs.use(['jquery-1.8.2.js', 'iscroll_module.js', 'mdialog_module.js', 'util_module.js', 'imgUpload_module.js', ], function(Z, I, M, U, IMG) {
		var curPage = 1;
		var pageSize = 4;
		var totalPage = 0;
		var user = U.checkLogin();
		var personVO;
		U.fillHead();
		U.fillFooter();
		var groupId = ''; //当前登录人的groupid
		var sendUser_groupId = ''; //发送团队通知消息的groupid
		var notice_id = ''; //当前用户查看的团队通知消息id
		initPage();
		//实例化编辑器
		var um = UM.getEditor('myEditor');
		$(".edui-container").width(568);
		$('.h_apply').css({
			'margin-right': '20px',
			'background': 'red',
			'float': 'right',
			'display': 'block',
			'height': '30px',
			'width': '70px',
			'text-align': 'center',
			'line-height': '30px',
			'margin-top': '15px',
			'display': 'none',
			'color': 'white'
		});
		$('.from>span:nth-child(2)').css('color', '#999999');

		function initPage() { //初始化页面
			if(user.state == 0) {
				$("body").empty();
				M.toast(false, "请先登录!", function() {
					U.loadLogin(true, false);
				});
			} else {
				$("body>div").not('.h_apply').show();
			}

			$(".write_date").val(U.getMyDate(new Date()));
			U.loadOpt(false);
			initEvent();
			menu_click();
			// 会员类型，0-普通用户，1企业会员,2-团体会员,3-贫困户,4，个人扶贫会员
			$('.menu>div').not('.community').hide();
			if(user.info.typ == 0) { //0-普通用户
				$('.menu>div').eq(0).show();
				$(".menu>div").eq(0).click();
				//$('#person_info').show();
				//user_info();
				$('.edit_btn').hide();

			} else if(user.info.typ == 1) { //1企业会员
				$('.menu>div').eq(1).show();
				$('.menu>div').eq(2).show();
				$('.menu>div').eq(6).show();
				$('.menu>div').eq(8).show();
				$(".menu>div").eq(1).click();
				//	$('#firm_info').show();
			} else if(user.info.typ == 2) { //2-团体会员,
				$('.basc_info').text('团体信息');
				$('.help_project').text('团体帮扶');
				$('.menu>div').eq(0).show();
				$('.menu>div').eq(5).show();
				$('.menu>div').eq(6).show();
				$('.menu>div').eq(8).show();
				console.info($('.m_list').length)
				if($('.m_list>ol').length==0){
					$('.dissolve').hide();
				}
				$(".menu>div").eq(0).click();
				//	$('#person_info').show();
				//team_info();
			} else if(user.info.typ == 3) { //3-贫困户,
				$('.menu>div').eq(0).show();
				$('.menu>div').eq(3).show();
				$('.menu>div').eq(4).show();
				$('.menu>div').eq(9).show();
				$(".menu>div").eq(0).click();
				//$('#poor_info').show();
				//poor_info();
			} else { //4，个人扶贫会员
				$('.menu>div').eq(0).show();
				$('.menu>div').eq(5).show();
				$('.menu>div').eq(8).show();
				check();
				$(".menu>div").eq(0).click();
				//	$('#person_info').show();
				//	user_info();
			}
			//$(".write_diary").click(); //进入写日记页面
		}

		function menu_click() {
			$(".menu>div").click(function() {
				$(".menu>div>div:nth-child(1)").width(0);
				$(".menu>div>div:last-child").text("");
				$(".menu>div").css("color", "black");
				$(this).find("div:nth-child(1)").width(2);
				$(this).find("div:last-child").text(">");
				$(this).css("color", "red");
				$(".right>div").hide();
				switch($(this).index()) {
					case 0:
						if(user.info.typ == 0) {
							user_info();
							$('#person_info').show();
						}
						if(user.info.typ == 1) {
							firm_info();
							$('#firm_info').show();
						}
						if(user.info.typ == 2) {
							team_info();
							$('#person_info').show();
						}
						if(user.info.typ == 3) {
							poor_info();
							$('#poor_info').show();
							$('.h_apply').hide();
						}
						if(user.info.typ == 4) {
							user_info()
							$('#person_info').show();
							$('.h_apply').hide();
						}

						break;
					case 1:
						curPage = 1;
						//获取企业信息
						firm_info();
						$('#firm_info').show();
						break;
					case 2:
						curPage = 1;
						//企业帮扶
						project_list();
						$("#paging").show();
						break;
					case 3:
						curPage = 1;
						$('.helping_diary').hide();
						$('.donate_record_list').show();
						$('.h_apply').hide();
						$('.donate_record_list').html('');
						get_record();
						$("#paging").show();
						//捐款记录
						break;
					case 4:
						//申请众筹
						curPage = 1;
						$('.hava_apply_donateRecord').show();
						$('.h_apply').show();
						$('.hava_apply_donateRecord').html('');
						$("#paging").show();
						get_repply_donated();
						break;
					case 5:
						//我的帮扶
						curPage = 1;
						project_list();
						$("#paging").show();
						break;
					case 6:
						//我的帮扶队员
						$('.My_helpful_member').show();
						get_my_teamMember();
						$("#paging").show();
						break;
					case 7:
						//我的帮扶任务
						curPage = 1;
						$('.my_poverty_alleviation_list').show();
						$("#paging").show();
						get_myTask();
						break;
					case 8:
						//日记
						curPage = 1;
						help_list();
						$("#paging").show();
						break;
					case 9:
						//家庭成员
						$('.p_Member_of_family_list').show();
						get_poorMember_list();
						break;
					case 10:
						//帮扶动态
						location.href = "dynamic.html";
						break;
				}
			});
		}

		function check() { //是否加入团队
			U.ajax('groupDetail/check/' + user.info.id, {}, function(json) {
				if(json.success) {
					if(json.models.groupDetailVO != null) {
						$('.menu>div').eq(7).show();
					}
				} else {

				}

			});

		}

		function user_info() {
			$('#poor_info').hide();
			$('#firm_info').hide();
			U.ajaxget("/person/detailByUid/" + user.info.id, {}, function(json) {
				if(json.success) {
					personVO = json.models.personVO;
					if(personVO.status == "0") {
						location.href = "apply.html";
						return false;
					}
					if(personVO.status == "1") {
						location.href = "wait_review.html";
						return false;
					}
					$(".helper_info .head_img>div:last-child>div:first-child>span:first-child").text(personVO.name);
					$($(".helper_info .head_img>div:first-child+div>div:first-child>span:first-child+span")[0]).text(personVO.sex == 1 ? "女" : "男");
					$(".phone").text(personVO.mobile);
					$(".weixin").text(personVO.weixin);
					$(".csxz").text(personVO.address);
					$(".szcs").text(personVO.city);
					var headImage = "../images/icons/icon_unknow.png";
					if(U.getImg(personVO.headImage).length > 0) {
						headImage = U.getImg(personVO.headImage)[0];
					}
					var otherImage = "../images/icons/default_card.png";
					if(U.getImg(personVO.otherImage).length > 0) {
						otherImage = U.getImg(personVO.otherImage)[0];
					}
					$(".head_img>div:first-child> img").attr("src", headImage);
					$(".fj img").attr("src", otherImage);
					$(".cardCode").text(personVO.cardCode);
					$(".bfdd").text(personVO.helpArea);
					$(".bffs").text(personVO.requirement);
					$(".bz").text(personVO.remark);
				} else {
					alert(json.errorMsg);
				}
			});
		}

		function team_info() {
			$('#firm_info').hide();
			$('#poor_info').hide();
			$('.other_info>div:nth-child(-n+3)').show();
			$('.other_info>div:nth-child(4)').hide();
			$('.other_info>div:nth-child(5)').hide();
			$('.sex_span').hide();
			$('.helper_address').hide();
			U.ajaxget("team/get/" + user.info.id, {}, function(json) {
				if(json.success) {
					userTeamVO = json.models.userTeamVO;
					groupId = userTeamVO.userGroupsVO.id;
					var teamType = userTeamVO.groupType == 1 ? '社会组织' : '志愿都协会';
					$(".helper_info .head_img>div:last-child>div:first-child>span:first-child").text(userTeamVO.principal);
					$(".phone").text(U.formPhone(userTeamVO.connectPhone));
					$(".weixin").text(userTeamVO.weixinId);
					$('.team_name').text(userTeamVO.name);
					$('.team_type').text(teamType);
					$('.team_intro').text(userTeamVO.intro);
					$(".bfdd").text(userTeamVO.helpArea);
					$(".bffs").text(userTeamVO.requiremrnt);
					$(".bz").text(userTeamVO.remark);
				}
			});
		}

		function firm_info() {
			$('#person_info').hide();
			$('#poor_info').hide();
			U.ajaxget('/entreprise/get/' + user.info.id, {}, function(json) {
				if(json.success) {
					var entrepriseVO = json.models.entrepriseVO;
					var status = entrepriseVO.status;
					if(entrepriseVO.userGroupsVO.id != null && entrepriseVO.userGroupsVO.id != undefined) {
						groupId = entrepriseVO.userGroupsVO.id;
					}
					var cardType = entrepriseVO.cardType == 1 ? '身份证' : '其它类型';
					$(U.getImg(entrepriseVO.bizImage)).each(function() {
						$('#fj1 img').attr('src', this);
					});
					var cardImages = "../images/icons/default_card.png";
					if(U.getImg(entrepriseVO.cardImages).length > 0) {
						cardImages = U.getImg(entrepriseVO.cardImages)[0];
					}
					$('#fj2 img').attr('src', cardImages);
					/*$(U.getImg(entrepriseVO.cardImages)).each(function() {
						$('#fj2 img').attr('src', this);
					});*/
					$('.firm_name').text(entrepriseVO.name);
					$('.weixin').text(entrepriseVO.connect)
					$('.phone').text(U.formPhone(entrepriseVO.tel));
					$('.code').text(U.formPhone(entrepriseVO.code));
					$('.legalPerson').text(entrepriseVO.legalPerson);
					$('.tel').text(entrepriseVO.tel)
					$('.card_type').text(cardType);
					$('.card').text(U.formPhone(entrepriseVO.cardCode))
					$('.address').text(entrepriseVO.address);
					$('.remark ').text(entrepriseVO.remark);
				} else {
					alert(json.msg);
				}
			});
		}

		function poor_info() {
			$('#person_info').hide();
			$('#firm_info').hide();
			U.ajaxget('/poverty/getByUser/' + user.info.id, {}, function(json) {
				if(json.success) {
					var povertyObjVO = json.models.povertyObjVO;
					//cardType = povertyObjVO.cardType == 1 ? '身份证' : '其它类型';

					var headImage = "../images/icons/icon_unknow.png";
					if(U.getImg(povertyObjVO.headImage).length > 0) {
						headImage = U.getImg(povertyObjVO.headImage)[0];
					}
					$('.head_imgs').attr('src', headImage);
					var otherImage = "../images/icons/default_card.png";
					if(U.getImg(povertyObjVO.images).length > 0) {
						otherImage = U.getImg(povertyObjVO.images)[0];
					}
					$('.fj img').attr('src', otherImage);
					var sex = povertyObjVO.sex == 2 ? '女' : '男';
					$('.poor_sex').text(sex);
					$('.poor_name').text(povertyObjVO.name);
					$('.poor_phone').text(U.formPhone(povertyObjVO.connect));
					$('.poor_cardCode').text(U.formPhone(povertyObjVO.cardCode));
					$('.poor_age').text(povertyObjVO.age);
					//						$('.bankCode').val(U.formPhone(povertyObjVO.bankCode));
					$('.poor_address').text(povertyObjVO.address);
					//$('.town_id').val(povertyObjVO.area);
					//$('.village_id').val(povertyObjVO.area);
					$('.poor_remark').text(povertyObjVO.remark);
					//$('.villageGroup').val(povertyObjVO.villageGroup);
					if(povertyObjVO.yAmountAvg == null || povertyObjVO.yAmountAvg == undefined) {
						povertyObjVO.yAmountAvg = '未知';
					}

					$('.poor_income').text(povertyObjVO.yAmountAvg);
					$('.poor_request').text(povertyObjVO.requirement);
					$('.poor_reason').text(povertyObjVO.reason);
					$('.poor_prasent').text(povertyObjVO.currentReason);
					$('.poor_count').text(povertyObjVO.personCount);
					var povertyObjPersonList = povertyObjVO.povertyObjPersonList;
					$('table').html('');
					$(".Member_of_family_list table").append("<tr class='family_list_title'><td>关系</td><td>姓名</td><td>年龄</td><td>性别</td><td>备注</td></tr>");
					$(povertyObjPersonList).each(function() {
						var sex = "未填写"
						if(this.sex == 1) {
							sex = "女";
						} else if(this.sex == 2) {
							sex = "男";
						}

						$(".Member_of_family_list table").append("<tr><td>" + this.relation + "</td><td>" + this.name + "</td><td>" + this.age + "</td><td>" + (sex) + "</td><td>" + this.remark + "</td></tr>");

					});

				} else {
					alert(json.msg);
				}
			});
		}

		function get_poorMember_list() { //获取贫困户家庭成员
			$('.p_Member_of_family_list table').html('');
			$('.p_Member_of_family_list table').append('<thead><tr class="family_list_title"><td>关系</td><td>姓名</td><td>年龄</td><td>性别</td><td>联系方式</td><td>有无劳动力</td><td>其他</td><td>备注</td><td>操作</td></tr></thead>');
			$('.p_Member_of_family_list td:last-child').css('width', '18%');
			U.ajaxget('/poverty/listPerson/' + user.info.id, {}, function(json) {
				if(json.success) {
					var result = json.models.povertyObjPersonList;
					$(result).each(function() {
						var sex = this.sex == 1 ? '女' : '男';
						if(this.connect == null) {
							this.connect = '未知';
						}
						var laboured = this.laboured == 1 ? '有' : '无';
						if(this.remark == null) {
							this.remark = '无';
						}
						if(this.others == null) {
							this.others = '无';
						}
						$(".p_Member_of_family_list table").append("<tr><td><input type='text' value=" + this.relation + " /> </td><td><input type='text' value=" + this.name + " /> </td><td><input type='text' value=" + this.age + " /> </td><td><input type='text' value=" + sex + " /> </td><td><input type='text' value=" + this.connect + " /> </td><td><input type='text' value=" + laboured + " /> </td><td><input type='text' value=" + this.others + " /> </td><td><input type='text' value=" + this.remark + " /> </td><td><span id=" + this.id + " class='p_edit'>编辑</span>&nbsp;&nbsp;&nbsp;&nbsp;<span id=" + this.id + " class='p_del'>删除</span></td></tr>");
					});
				} else {
					alert(json.errorMsg);
				}

				$('.p_edit').click(function() { //修改家庭成员信息
					var temp = $(this).parent().parent();
					temp.find('input').css('border', '1px solid black');
					$(this).text('保存');
					$(this).click(function() {
						if($(this).text().trim() == '保存') {
							var sex = temp.find('td:nth-child(4)').find('input').val();
							if(sex == '男') {
								sex = 2;
							} else if(sex == '女') {
								sex = 1;
							} else {
								sex = 0;
							}
							var laboured = temp.find('td:nth-child(6)').find('input').val();
							if(laboured == '有') {
								laboured = 1;
							} else if(laboured == '无') {
								laboured = '0'
							}
							var param = {
								'name': temp.find('td:nth-child(2)').find('input').val(),
								'relation': temp.find('td:nth-child(1)').find('input').val(),
								'age': temp.find('td:nth-child(3)').find('input').val(),
								'connect': temp.find('td:nth-child(5)').find('input').val(),
								'remark': temp.find('td:nth-child(8)').find('input').val(),
								'sex': sex,
								'laboured': laboured,
								'others': temp.find('td:nth-child(7)').find('input').val(),
								'pid': user.info.id,
								'id': $(this).attr('id')
							}
							U.ajaxget('/poverty/updatePerson', param, function(json) {
								if(json.success) {
									alert('修改成功!');
									$(".menu>div").eq(10).click();
								} else {
									alert(json.errorMsg);
								}

							});
						}

					});

				});
				$('.p_del').click(function() { //删除家庭成员信息
					var temp = $(this).parent().parent();
					U.ajaxget('/poverty/delPerson/' + $(this).attr('id'), {}, function(json) {
						if(json.success) {
							alert('删除成功!')
							temp.remove();
						} else {
							alert(json.errorMsg);
						}
					});
				});
			});

		}

		function project_list() { //我 的帮扶
			$(".my_poverty_alleviation").empty();
			var params = {
				uid: user.info.id,
				curPage: curPage,
				pageSize: pageSize
			}
			U.ajaxget("/project/getbyuid/" + user.info.id + "/1", {}, function(json) {
				if(json.success) {
					$(json.models.projectList).each(function() {
						var jindu = "../images/icons/icon_weizhankai.png";
						if(this.state == 1) {
							jindu = "../images/icons/icon_weizhankai.png"; //<!--未开展-->
						}
						if(this.state == 2) {
							jindu = "../images/icons/icon_jinxinzhong.png"; //<!--进行中-->
						}
						if(this.state == 3) {
							jindu = "../images/icons/icon_xiangmujieshu.png"; //<!--项目结束-->
						}
						var project = "<div id='" + this.id + "'><div>" + this.title + "</div><div>" + this.intro + "</div><div>" + U.getMyDate(this.gmtCreate) + "</div><img src='" + jindu + "'></div>";
						$(".my_poverty_alleviation").append(project);
						$('.my_poverty_alleviation_list').show();
					});
					paging_handle(json.models.page, project_list);
					details_click();
				} else {
					alert(json.errorMsg);
				}
			});
		}

		function get_record() { //查询被捐款记录
			var param = { 'crowdId': 0, 'curPage': curPage }
			U.ajax('/support/list', param, function(json) {
				if(json.success) {
					var result = json.models.supportRecordList;
					$(result).each(function() {
						this.images = U.getImg(this.images)[0];
						if(this.images == undefined || this.images == undefined) {
							this.images = '../images/icons/loadfail.png';
						}
						$('.donate_record_list').append('<div id=' + this.id + ' class="record"><img src="' + this.images + '"><div class="donate_title">' + this.title + '</div><div class="donate_time">' + U.getMyDate(this.gmtCreate) + '</div><div class="donate_money">支付金额：￥' + this.amount + '</div></div>');
					});
					paging_handle(json.models.page, get_record);
					$('.record').click(function() { ////捐款众筹记录
						location.href = 'donate_detail.html?id=' + $(this).attr('id');
					});
				} else {
					alert(json.errorMsg);
				}
			});
		}

		function get_repply_donated() { //申请众筹记录
			U.ajaxget('/crowd/listByUserId/' + user.info.id, {}, function(json) {
				if(json.success) {
					var result = json.models.crowdList;
					$(result).each(function() {
						type = this.typ == 1 ? '众筹' : '捐款';
						var status = this.status;
						if(status == 0) {
							status = '待审核';
						} else if(status == 1) {
							status = '待审通过';
						} else {
							status = '未通过';
						}
						$('.hava_apply_donateRecord').append('<div id=' + this.id + ' class="h_record"><div class="h_title"><span>' + this.title + '</span> <span class="h_status">' + status + '</span></div><div class="h_detail">描述：' + this.intro + '</div><div class="h_money">目标金额：￥' + this.amount + '</div><div class="h_time">' + U.getMyDate(this.gmtCreate) + '</div></div>');

					});
					$('.h_apply').unbind('click').click(function() { //申请众筹
						$('.hava_apply_donateRecord').hide();
						$('.doante_detail_apply').show();
						$('.h_apply').hide();
						$('.home_span,.center_span').hide();
						$('.h_back').show();
						$('.h_submit').show();
						$('.upload_fj').show();
						$('.doante_detail_apply input,.doante_detail_apply textarea').val('');
						$('#fj_img1 img').attr('src', '../images/icons/upload.png');
						$('.doante_detail_apply input,.doante_detail_apply textarea').css('border', '1px solid black');
					});
					$('.h_record').click(function() { //申请众筹详情
						$('.hava_apply_donateRecord').hide();
						$('.h_apply').hide();
						$('.home_span,.center_span').hide();
						$('.h_back').show();
						$('.doante_detail_apply').show();
						$('.doante_detail_apply input,.doante_detail_apply textarea').css('border', 'none');
						$('.h_submit').hide();

						U.ajaxget('/crowd/edit/' + $(this).attr('id'), {}, function(json) {
							if(json.success) {
								var crowdVO = json.models.crowdVO;
								var status = crowdVO.status;
								if(status == 0) {
									status = '待审核';
								} else if(status == 1) {
									status = '待审通过';
								} else {
									status = '未通过';
								}
								$('.d_title').val(crowdVO.title);
								$('.d_money').val(crowdVO.amount);
								$('.d_content').val(crowdVO.intro);
								$('#fj_img1 img').attr('src', U.getImg(crowdVO.images));
								$('.d_type>option:first-child').text(type);
								$('.d_remark').val(crowdVO.remark);
								$('.h_submit').hide();
								$('.upload_fj').hide();
							} else {
								M.toast(false, json.msg)
							}
						});

					});
				} else {
					alert(json.errorMsg);
				}
			});
		}

		function help_list() { //日记
			$('.helping_diary').show();
			$(".notice_list>ul").empty();
			var params = {
				uid: user.info.id,
				curPage: curPage,
				pageSize: pageSize
			}
			U.ajaxget("/userlogs/byUid/" + user.info.id + "/" + curPage, {}, function(json) {
				if(json.success) {
					$(json.models.userLogsList).each(function() {
						var log = "<li id='" + this.id + "'><img src='../images/icons/icon_dian.png'><div>" + this.title + "</div><span>" + U.getMyDate(this.gmtCreate) + "</span></li>";
						$(".notice_list>ul").append(log);
					});
					paging_handle(json.models.page, help_list);
					details_click();
				} else {
					alert(json.errorMsg);
				}
			});
		}

		function details_click() { //日记详情
			$(".my_poverty_alleviation>div").unbind("click").click(function() {
				window.open("project_details.html?id=" + $(this).attr("id"));
			});
			$(".notice_list li").click(function() {
				$(".right>div").hide();
				U.loadOpt(true);
				U.ajaxget("/userlogs/detail/" + $(this).attr("id"), {}, function(json) {
					U.loadOpt(false);
					if(json.success) {
						var userLogsVO = json.models.userLogsVO;
						$(".log_view>div:nth-child(1)>div:last-child").text(userLogsVO.title);
						$(".log_view>div:nth-child(2)>div:last-child").text(U.getMyDate(userLogsVO.gmtCreate));
						$(".log_view>div:nth-child(3)>div:last-child").html(userLogsVO.content);
						$(".log_view").show();
					} else {
						alert(json.errorMsg);
					}
				});
			});
		}

		function get_myTask() { //（个人）我的帮扶任务
			$('.list').html('');
			U.ajaxget('/mission/getByUserId/' + user.info.id, {}, function(json) {
				if(json.success) {
					var result = json.models.missionList;
					$(result).each(function() {
						var status = this.state;
						if(status == 0) {
							status = '未完成';
						} else {
							status = '已完成';
						}
						$('.list').append('<ol><li>' + this.title + '</li><li>' + U.getMyDate(this.beginTime) + '</li><li>' + U.getMyDate(this.endTime) + '</li><li>' + status + '</li></ol>');
					});
				} else {
					alert(json.errorMsg);
				}
			});

		}

		function get_teamNotice_list() { //获取团队通知列表
			$('.team_notice_list').html('');
			var param = {
				'acceptUser': user.info.id,
				'curPage': curPage,
				'pageSize': pageSize
			}
			U.ajax('/userMessage/queryByState/', param, function(json) {
				if(json.success) {
					var result = json.models.uList;
					$(result).each(function() {
						$('.team_notice_list').append('<div id=' + this.id + '><span></span><span>' + this.title + '</span><span>' + U.getMyDate(this.gmtCreate) + '</span></div>');
					});
					paging_handle(json.models.page, get_teamNotice_list);
				} else {
					alert(json.errorMsg);
				}
				$('.team_notice_list>div').click(function() { //查看通知详情
					$('.team_notice_list').hide();
					$('.team_notice_detail').show();
					var id = $(this).attr('id')
					U.ajax('/userMessage/queryByState/', param, function(json) {
						if(json.success) {
							var result = json.models.uList;
							$(result).each(function() {
								if(this.id == id) {
									$('.content').html(this.content);
									notice_id = this.id;
								}
							});
							sendUser_groupId = $('.content .aggree').attr('groupid');
							is_aggree();
							$('.content>div').eq(3).find('span:nth-child(3)').css('margin-left', '20px');
							$('.content>div:nth-child(6)').find('div:first-child').css('margin-left', '60px')
						} else {
							alert(json.errorMsg);
						}
					});
				});
			});
		}

		function change_notice_state(id) { //接受、拒绝消息后更改状态
			var param = {
				'id': id
			}
			U.ajax('/userMessage/changeState/', param, function(json) {
				if(json.success) {} else {
					alert(json.errorMsg);
				}

			});
		}

		function is_aggree() { //接受或拒绝
			var is_join = false;
			$('.content>div:nth-child(6)').find('span').click(function() {
				if($(this).text().trim() == '同意') {
					U.ajaxAsync('groupDetail/check/' + user.info.id, {}, function(json) {
						if(json.success) {
							if(json.models.groupDetailVO !== null) {
								alert('您已加入过团体，不能再加入!');
								is_join = true;
							} else {
								join_team();
							}
						} else {
							alert(json.errorMsg);
						}
					});
				}
				if($(this).text().trim() == '拒绝') {
					change_notice_state(notice_id);
				}

			});

		}

		function join_team() {
			var param = {
				'mobile': user.info.mobile,
				'groupId': sendUser_groupId,
				'position': $('.content>div:first-child').find('span:last-child').text() //1 同意  2拒绝
			}
			U.ajax('/groupDetail/addGroup/', param, function(json) {
				if(json.success) {
					alert('您已成功加入该团体!')
					change_notice_state(notice_id);
				} else {

					alert(json.errorMsg);
				}
			});
		}

		function get_my_teamMember() { //我的帮扶队员
			$('.m_list').html('');
			var param = {
				curPage: curPage,
				pageSize: pageSize,
				groupId: groupId
			}
			if(groupId == null || groupId == undefined || groupId == '') {
				alert('暂未有团队');
				return;
			}
			// <span class="m_edit">编辑</span> <span class="apoint_task">任务指派</span>
			// <span>等待加入</span>
			U.ajax('/groupDetail/queryBygroup', param, function(json) {
				if(json.success) {
					var result = json.models.groList;
					$(result).each(function() {
						$('.m_list').append('<ol groupId=' + this.groupId + '  id=' + this.id + ' ><li>' + this.name + '</li><li>' + this.position + '</li><li>' + this.mobile + '</li><li>' + this.weixin + '</li><li>' + this.city + '</li><li> <span class="apoint_task">任务指派</span></li></ol>');
					});
					paging_handle(json.models.page, get_my_teamMember);
					$('.apoint_task').click(function() { //指派任务
						location.href = 'apoint_task.html?uid=' + $(this).parent().parent().attr('id');
					});
				}
			});
		}

		function initEvent() {
			$('.new_add_member').click(function() { //弹出添加队员窗口
				U.loadBackground(true);
				$('.add_member_view').show();
			});
			/*添加队员*/
			$('.m_submit').click(function() {
				var userId = '';
				if(!(/^1[34578]\d{9}$/.test($('.m_phone').val()))) {
					alert("手机号码有误，请重填");
					return false;
				}
				if($('.m_position').val().trim() == '') {
					alert('请填写职位');
					return false;
				}
				U.ajax('/user/queryUserId/' + parseInt($('.m_phone').val()), {}, function(json) {
					if(json.success) {
						userId = json.models.userId;
						var params = {
							'userId': userId,
							'groupId': groupId,
							'position': $('.m_position').val()
						}
						U.ajax('/userMessage/send/', params, function(json) {
							if(json.success) {
								U.loadBackground(false);
								$('.add_member_view').hide();
								alert('邀请成功,请等待消息!');
							} else {
								alert(json.errorMsg);
							}
						});
					} else {
						alert(json.errorMsg);
					}
				});
			});
			/*解散团队*/
			$('.dissolve').click(function() {
				U.ajax('groupDetail/dissolve/'+groupId, {}, function(json) {
					if(json.success) {
						M.toast(true, '已成功解散团队队员！', function() {
							$(".menu>div").eq(6).click();
						})
					} else {
						alert(json.errorMsg);
					}
				});

			});
			/*退出团队*/
			$('.exit_team').click(function() {
				U.ajax('groupDetail/exit', {}, function(json) {
					if(json.success) {
						M.toast(true, '已成功退出团队！', function() {
							location.reload();
						})
					} else {
						alert(json.errorMsg);
					}
				});

			});
			$('.img_div img').click(function() {
				U.loadBackground(false);
				$('.add_member_view').hide();
			});
			/*团队通知消息*/
			$('.team_msg').click(function() {
				$('.my_poverty_alleviation_list').hide();
				$('.team_notice_list').show();
				get_teamNotice_list();
				$("#paging").show();
			});
			$('.h_back').click(function() { //返回
				$(".menu>div").eq(4).click();
				$('.home_span,.center_span').show();
				$('.h_back').hide();

			});
			/*上传申请众筹照片*/
			$(".upload_fj").click(function() {
				$(this).next().click();
			});
			IMG.uploadImg({
				'obj': $('#fj1'),
				'success': function(json, obj) {
					U.loadOpt(false);
					if(json.state == "SUCCESS") {
						$("#fj_img1 img").attr("uploadimg", json.url + "");
						$("#fj_img1 img").attr("src", json.url + "");

					} else {
						M.toast(false, "上传失败！");
					}
				},
				'error': function(msg) {
					M.error(msg);
				}
			});
			/*申请众筹捐款*/
			$('.h_submit').click(function() {
				/*var otherImage = "../images/icons/default_card.png";
				if(U.getImg(personVO.otherImage).length > 0) {
					otherImage = U.getImg(personVO.otherImage)[0];
				}*/
				var crowdVO = {
					userId: user.info.id, //(会员ID： 只有贫困户才可以发起众筹),
					title: $('.d_title').val(), // 众筹（ 标题）,
					amount: $('.d_money').val(), //(众筹金额， 以元为单位),
					intro: $('.d_content').val(), //项目描述(项目描述),
					images: $("#fj_img1 img").attr('src'), //image.pingjiang.gov.cn/....(图片：多张图片用","分隔开),
					typ: $('.d_type').val(), //(项目类型： 1 - 众筹， 2 - 捐款),
					remark: $('.d_remark').val() //备注(备注),
				}
				var num = /^[0-9]*[1-9][0-9]*$/;
				if(!num.test($('.d_money').val())) {
					M.toast(false, '请输入正整数');
					return;
				}
				if($('.d_title').val().trim() == '' || $('.d_money').val().trim() == '' || $('.d_content').val().trim() == '') {
					M.toast(false, '请填写完整信息');
					return;
				}
				var temp = $(".menu>div").eq(4);
				U.ajax('/crowd/add', crowdVO, function(json) {
					if(json.success) {
						alert('申请成功!');
						temp.click();
					} else {
						alert(json.errorMsg);

					}
				});

			});
			/*添加家庭成员*/
			$('.p_add').click(function() {
				$('.p_Member_of_family_list').hide();
				$('.add_member').show();
				$('.add_member input').val('');
				$('.home_span,.center_span').hide();
				$('.p_back').show();
			});
			$('.p_back').click(function() {
				$(".menu>div").eq(10).click();
			});
			$('.add_btn').click(function() {
				var param = {
					'name': $('.add_member>div:nth-child(2)').find('input').val(),
					'relation': $('.add_member>div:nth-child(3)').find('input').val(),
					'age': $('.add_member>div:nth-child(5)').find('input').val(),
					'connect': $('.add_member>div:nth-child(7)').find('input').val(),
					'remark': $('.add_member>div:nth-child(8)').find('input').val(),
					'sex': $('.member_sex').val(),
					'laboured': $('.member_laboured').val(),
					'others': $('.add_member>div:nth-child(9)').find('input').val(),
					'pid': user.info.id
				}
				U.ajaxget('/poverty/addPerson', param, function(json) {
					if(json.success) {
						alert('添加成功！');
						$(".menu>div").eq(10).click();

					} else {
						alert(json.errorMsg);
					}
				});
			});
			/*添加日志*/
			$(".save_btn").unbind("click").click(function() {
				var log_title = $(".write_view>div:nth-child(1) input").val();
				//var log_author = $(".write_view>div:nth-child(3) textarea").val();
				var log_author = UM.getEditor('myEditor').getContent();
				var log_time = $(".write_view>div:nth-child(2) input").val();

				if(log_time == "" || log_author == "" || log_title == "") {
					M.toast(false, "请填写完整信息");
					return false;
				}
				var params = {
					userId: user.info.id,
					title: log_title,
					content: log_author
				}
				U.ajax("/userlogs/add", params, function(json) {
					if(json.success) {
						alert("保存成功！");
						$(".write_view>div:first-child input").val("");
						UM.getEditor('myEditor').setContent("");
						//$(".write_view>div>div:last-child textarea").val("");
						$(".menu>div").eq(3).click();
					} else {
						alert(json.errorMsg);
					}
				});
			});
			/*编辑个人信息*/
			$(".edit_btn").click(function() {
				var user_type = user.info.typ;
				if(user_type == 0) {
					location.href = "personal_apply_edit.html?type=edit";
				} else if(user_type == 1) {
					location.href = 'apply_business.html?type=edit';
				} else if(user_type == 2) {
					location.href = "team_apply_edit.html?type=edit";
				} else if(user_type == 3) {
					location.href = 'poor_people_edit.html?type=edit';
				} else {
					location.href = 'personal_apply_edit.html?type=edit';
				}

			});
			$(".exit_login").click(function() { //退出登录
				U.writeCookie("fp_user", "", 1);
				U.writeCookie("www-pjfp-com", "", 1);
				location.href = "index.html";
			});

			$(".write_diary").click(function() {
				$(".right>div").hide();
				$(".write_view").show();
			});
		}

		function paging_handle(page, method) {
			//分页导航数据处理
			totalPage = page.totalPage;
			$("#paging .page").empty();
			var start_count = 0;
			try {
				if(curPage >= 10) {
					start_count = curPage - 5;
				}
			} catch(e) {}
			var lastsize = totalPage;
			lastsize = start_count + 10;

			if(lastsize >= totalPage) {
				lastsize = totalPage;
			}
			for(var i = start_count; i < lastsize; i++) {
				if(i + 1 == curPage) {
					$("#paging .page").append("<div style='color:white;border-color:white;background-color:#DC3F44'>" + (i + 1) + "</div>");
				} else {
					$("#paging .page").append("<div>" + (i + 1) + "</div>");
				}
			}
			$(".Record>span:nth-child(1)").text("共" + page.totalItem + "条记录");
			$(".Record>span:nth-child(2)").text(curPage + "/" + page.totalPage);
			$("#paging .goto_page>input").val(curPage);
			//分页导航数据处理完毕
			//处理单击事件
			$(".next_page").unbind("click").click(function() {
				if(!page.nextPage) {
					alert("已经是最后一页了!")
					return false;
				}
				curPage++;
				method();
			});
			$(".up_page").unbind("click").click(function() {
				if(curPage == 1) {
					alert("已经是第一页了!");
					return false;
				}
				curPage--;
				method();
			});
			$("#paging .page>div").unbind("click").click(function() {
				curPage = $(this).text();
				method();
			});
			$("#paging .goto").unbind("click").click(function() {
				try {
					var index = $("#paging .goto_page>input").val();
					if(index <= totalPage && index > 0 && !/^[+-]?[1-9]?[0-9]*\.[0-9]*$/.test(index)) {
						curPage = $("#paging .goto_page>input").val();
						method();
					} else {
						alert("请输入正确的页码！");
					}
				} catch(e) {
					alert("请输入正确的页码！");
				}
			});
			//单机事件绑定完毕

		}
	});
}